package logic

import (
	"context"
	"errors"

	"test-api/internal/model"
	"test-api/internal/svc"
	"test-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserCreateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserCreateLogic {
	return &UserCreateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserCreateLogic) UserCreate(req *types.STUserCreateReq) (resp *types.STUserCreateRsp, err error) {
	resp = &types.STUserCreateRsp{}

	if err = l.svcCtx.DB.Create(&model.User{
		Name:   req.Name,
		Mobile: req.Mobile,
		State:  1,
	}).Error; err != nil {
		return resp, errors.New("数据库错误")
	}

	return resp, nil
}
